for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
tmp = [i for i in range(n)]
tmp.sort(key=lambda i: [a[i], b[i]])
for i in range(n - 1):
if a[tmp[i]] > a[tmp[i + 1]] or b[tmp[i]] > b[tmp[i + 1]]:
print("-1")
break
else:
ans = []
for i in range(n - 1):
for j in range(n - 1):
if a[j] > a[j + 1] or b[j] > b[j + 1]:
a[j], a[j + 1] = a[j + 1], a[j]
b[j], b[j + 1] = b[j + 1], b[j]
ans.append([j + 1, j + 2])
print(len(ans))
for it in ans:
print(*it)
#include <bits/stdc++.h>
using namespace std;
// -----------------------------------------------------------------
void test(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
// -----------------------------------------------------------------
#define FastIO cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
#define printv(v) for(auto x:v){cout<<x<<" ";}cout<<endl;
#define dbg(x) cout<<#x<<" = "<<x<<endl;
#define SQ(a) (a)*(a)
#define PB push_back
#define S second
#define F first
// -----------------------------------------------------------------
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> mi;
typedef vector<vii> mii;
// --------------------------------------
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector< ll > vll;
typedef vector< pll > vpll;
typedef vector< vll > mll;
typedef vector< vpll > mpll;
typedef unsigned long long ull;
typedef long double ld;
// --------------------------------------
const ll INF = 9223372036854775807;
const int OO = 2147483647;
const ll MOD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.141592653589793238;
const int TOW = 0b10;
const int FIFTEEN = 0xf;
int tc = 1;
// -----------------------------------------------------------------
const int N = 3e5 + 5e3;
ll n;
pair<ii,int> a[105], b[105];
vii ans;
// --------------------------------------
// --------------------------------------
void doTest(){
cin>>n;
for(int i = 0 ; i < n ; i ++){
cin>>a[i].F.F;
b[i].F.F = a[i].F.F;
}
for(int i = 0 ; i < n ; i ++){
cin>>a[i].F.S;
a[i].S = i+1;
b[i].F.S = a[i].F.S;
}
sort(a, a+n);
for(int i = 1 ; i < n ; i ++){
if(a[i].F.S < a[i-1].F.S){
cout<<-1<<endl;
return;
}
}
ans.clear();
for(int i = 0 ; i < n-1 ; i ++){
for(int j = 1 ; j < n-i ; j ++){
if(b[j-1].F > b[j].F){
ans.push_back({j, j+1});
ii tmp = b[j].F;
b[j].F = b[j-1].F;
b[j-1].F = tmp;
}
}
}
cout<<ans.size()<<endl;
for(int i = 0 ; i < ans.size() ; i ++){
cout<<ans[i].F<<" "<<ans[i].S<<endl;
}
}
// --------------------------------------
int main(){
test();
FastIO
cout<<fixed<<setprecision(15);
// scanf("%d",&tc);
cin>>tc;
while(tc--) doTest();
}
// -----------------------------------------------------------------
322. Coin Change | 307. Range Sum Query - Mutable |
287. Find the Duplicate Number | 279. Perfect Squares |
275. H-Index II | 274. H-Index |
260. Single Number III | 240. Search a 2D Matrix II |
238. Product of Array Except Self | 229. Majority Element II |
222. Count Complete Tree Nodes | 215. Kth Largest Element in an Array |
198. House Robber | 153. Find Minimum in Rotated Sorted Array |
150. Evaluate Reverse Polish Notation | 144. Binary Tree Preorder Traversal |
137. Single Number II | 130. Surrounded Regions |
129. Sum Root to Leaf Numbers | 120. Triangle |
102. Binary Tree Level Order Traversal | 96. Unique Binary Search Trees |
75. Sort Colors | 74. Search a 2D Matrix |
71. Simplify Path | 62. Unique Paths |
50. Pow(x, n) | 43. Multiply Strings |
34. Find First and Last Position of Element in Sorted Array | 33. Search in Rotated Sorted Array |